
/*Entry Cost Analysis
STATA 14
January 15, 2017
Replicates Apppendix 7 - Parallel Trends and Robustness Tests*/


cd  "C:\Users\ejm5\Dropbox\Rents_Asunder\CountryofOrigin\20160315_InternationaOrganization\Replication"
use  oecd_7years_working.dta, clear
log using parallel.smcl, replace
pause on


/*Different Demarcations for Phase 3*/

#delimit;
xi: reg c6 phase1 ;
outreg2 using 201601116_Parallel,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) replace;

#delimit;
set more off;
foreach num of numlist 1997(1)2015 {;
generate cut_`num'=1 if a1>`num' & a1 !=. & a1 !=.b;
replace cut_`num'=0 if a1<=`num';
generate inter_`num'=cut_`num'*oecd;
xi: reg c6 cut_`num' oecd inter_`num' i.year  a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2   if treatment==0 & a1<=`num'+6, cluster(pci_id);
predict ns_items;
generate bribe=c6-ns_items;
xi: reg bribe cut_`num' oecd inter_`num'  i.year  a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2   if treatment==1 & a1<=`num'+6, cluster(pci_id);
generate beta_`num'= _b[inter_`num'];
generate se_`num'= _se[inter_`num'];
gen tcrit_`num'=invttail(e(df_r), .025);
outreg2 using 201601116_Parallel,  bdec(3) tdec(3) e(N N_clust r2 rmse ll );
drop ns_items bribe;
};


#delimit;
xi: reg c6 phase1;
outreg2 using 201601116_Parallel,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) excel;




collapse beta* se_* tcrit_*;
generate id=_n;;
reshape long beta_ se_ tcrit_, i(id) j(year);
generate low_ci= beta_-tcrit_*se_;
generate hi_ci= beta_+tcrit_*se_;

#delimit;
twoway (rspike  low_ci hi_ci year, lwidth(medium) lcolor(gs7)) 
(scatter  beta_ year, msize(small) msymbol(diamond) mcolor(purple)), 
yline(0, lwidth(medthick) lpattern(dash)) title("Different Phase 3 Demarcation Year (After> Entry Year)", size(large)) 
ytitle("Diff-in-Diff Coefficient") legend(off)
xlab(1997(1)2015, labsize(medsmll) angle(45)) ylab(-.8(.2).8, labsize(vsmall)) xtitle("")  
xline(2009, lwidth(vvvthick) lcolor(ltblue)) scheme(s1mono);
graph save ydemarcation.gph, replace;

/****************************************************************/

/*Initial Entry Year*/
#delimit;
use  oecd_7years_working.dta, clear;
set more off;


#delimit;
xi: reg c6 phase1 ;
outreg2 using 201601116_Parallel2,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) replace;

#delimit;
foreach num of numlist 1997(1)2009{;
xi: reg c6 phase3 oecd inter_p3oecd i.year  a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2   if treatment==0  & a1>=`num', cluster(pci_id) ;
predict ns_items;
generate bribe=c6-ns_items;
xi: reg bribe phase3 oecd inter_p3oecd  i.year  a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2 if treatment==1 & a1>=`num', cluster(pci_id);
generate beta_`num'= _b[inter_p3oecd];
generate se_`num'= _se[inter_p3oecd];
gen tcrit_`num'=invttail(e(df_r), .025);
outreg2 using 201601116_Parallel2,  bdec(3) tdec(3) e(N N_clust r2 rmse ll );
drop ns_items bribe;
};


#delimit;
xi: reg c6 phase1;
outreg2 using 201601116_Parallel2,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) excel;



#delimit;
collapse beta* se_* tcrit_*;
generate id=_n;;
reshape long beta_ se_ tcrit_, i(id) j(year);
generate low_ci= beta_-tcrit_*se_;
generate hi_ci= beta_+tcrit_*se_;

#delimit;
twoway (rspike  low_ci hi_ci year, lwidth(medium) lcolor(gs7)) 
(scatter  beta_ year, msize(small) msymbol(diamond) mcolor(purple)), 
yline(0, lwidth(medthick) lpattern(dash)) title("Earliest Entry Year Allowed", size(large)) 
ytitle("Diff-in-Diff Coefficient") 
xlab(1997(1)2009, labsize(vsmll) angle(45)) ylab(-.8(.2).2, labsize(vsmall)) xtitle("")  
xline(2000, lwidth(vvvthick) lcolor(ltblue))
legend(rows(1) size(vsmall) ring(0) position(7) label(1 95% Confidence Interval) label(2 Beta)) scheme(s1mono);
graph save yinitial.gph, replace;
graph export yinitial.pdf, as(pdf) replace;




/****************************************************************/

/*Bandwidth*/
#delimit;
use  oecd_7years_working.dta, clear;
set more off;


#delimit;
xi: reg c6 phase1 ;
outreg2 using 20161125_Parallel3,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) replace;

#delimit;
foreach num of numlist 1(1)9{;
xi: reg c6 phase3 oecd inter_p3oecd  i.year a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2   if treatment==0 & a1>=2009-`num' & a1<=2009+`num', cluster(pci_id);
predict ns_items;
generate bribe=c6-ns_items;
xi: reg bribe phase3 oecd inter_p3oecd i.year  a6_1 a6_2 a6_3 a6_4 a6_5 hundred  labor_est  d2   ln_pop if treatment==1 & a1>=2009-`num' & a1<=2009+`num', cluster(pci_id);
generate beta_`num'= _b[inter_p3oecd];
generate se_`num'= _se[inter_p3oecd];
gen tcrit_`num'=invttail(e(df_r), .05);
outreg2 using 20161125_Parallel3,  bdec(3) tdec(3) e(N N_clust r2 rmse ll );
drop ns_items bribe;
};



xi: reg c6 phase1;
outreg2 using 20161125_Parallel3,  bdec(3) tdec(3) e(N N_clust r2 rmse ll ) ci level(90) excel;




collapse beta* se_* tcrit_*;
generate id=_n;;
reshape long beta_ se_ tcrit_, i(id) j(bandwidth);
generate low_ci= beta_-tcrit_*se_;
generate hi_ci= beta_+tcrit_*se_;

#delimit;
twoway (rspike  low_ci hi_ci bandwidth, lwidth(medium) lcolor(gs7)) 
(scatter  beta_ bandwidth, msize(small) msymbol(diamond) mcolor(purple)), 
yline(0, lwidth(medthick) lpattern(dash)) title("Bandwidth: Years Before and After Phase 3", size(large)) 
ytitle("Diff-in-Diff Coefficient") legend(off)
xlab(1(1)9, labsize(medsmall)) ylab(-.8(.2).4, labsize(vsmall)) xtitle("")
legend(rows(2) size(vsmall) ring(0) position(11) label(1 95% Confidence Interval) label(2 Beta)) scheme(s1mono) ;
graph save bandwidth.gph, replace;

#delimit;
graph combine ydemarcation.gph  bandwidth.gph yinitial.gph, rows(3) imargin(tiny) scheme(s1mono) note("Range Bars = 90% CI");
graph save robustness_tests.gph, replace;
graph export Appendix7.pdf, as(pdf) replace;
pause;

/***********************************************************Parallel Trends Graphic*************************************/ 

#delimit cr
use  oecd_7years_working.dta, clear
set more off
generate est_year5=a1
replace est_year5=1989 if a1<=1989
replace est_year5=1994 if a1>1989 & a1<=1994
replace est_year5=1999 if a1>1994 & a1<=1999
replace est_year5=2004 if a1>1999 & a1<=2004
replace est_year5=2009 if a1>2004 & a1<=2009
replace est_year5=2014 if a1>2009
drop if a1==.
drop if a1==.b

collapse (mean) c6, by(treatment oecd est_year5)
by oecd est_year, sort: egen min=min(c6)
by oecd est_year, sort: egen max=max(c6)
generate bribe=(max-min)*100


#delimit;
twoway  (line bribe est_year if oecd==0 & est_year>=1989, lcolor(maroon) lpattern(dash) lwidth(medthick))
(scatter bribe est_year if oecd==0 & est_year>=1989, msymbol(triangle) mcolor(maroon) msize(medlarge)) 
(line bribe est_year if oecd==1& est_year>=1989, lcolor(navy) lwidth(medthick)) 
(scatter bribe est_year if oecd==1& est_year>=1989, msymbol(diamond) mcolor(navy) msize(medlarge)), 
xlab(1989(5)2014) xline(2009.5, lcolor(red) lwidth(thick))
ytitle("Firms Paying Bribe at Registration (%)", size(medium) margin(medium))
xtitle("Establishment Year (5 Year Averages)", size(medium) margin(medium))
legend(rows(4) size(small) label(1 Non-OECD) label(3 OECD Signatory) label(2 "") label(4 "")
ring(0) position(7))
note("Bar denotes start of OECD-ACB Phase 3 after December, 2009", size(small) position(7)) scheme(s1mono);
graph save trends_test.gph, replace;
graph export Appendix7_1.pdf, as(pdf) replace;
pause;

log close;



